package com.asset.dispoal.channel.service.common;

import com.asset.dispoal.channel.dto.SysChannelRequest;
import com.asset.dispoal.channel.domain.db.entity.SysChannel;
import com.asset.dispoal.channel.domain.db.mapper.SysChannelMapper;
import com.asset.dispoal.channel.service.converter.SysChannelConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.date.DateTimeUtil;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.core.id.BaseIdeable;
import tech.mhuang.pacebox.springboot.protocol.Result;

import java.math.BigDecimal;

/**
 * @author qr
 * @date 2022/3/25$
 */
@Component
public class SysChannelInsertCommand implements BaseCommand<SysChannelRequest, Result> {

    @Autowired
    SysChannelMapper sysChannelMapper;

    @Autowired
    private BaseIdeable<String> ideable;

    @Override
    public Result execute(SysChannelRequest request) {
        SysChannel sysChannel = SysChannelConverter.INSTANCE.resToDo(request);
        sysChannel.setId(ideable.generateId());
        sysChannel.setCreateTime(DateTimeUtil.currentDate());
        sysChannel.setUpdateTime(DateTimeUtil.currentDate());
        sysChannel.setOpenMoney(BigDecimal.ZERO);
        sysChannel.setPayMoney(BigDecimal.ZERO);
        sysChannel.setTotalMoney(BigDecimal.ZERO);
        sysChannelMapper.insert(sysChannel);
        return Result.ok();
    }
}
